import { BasicColumn, useRender, FormSchema } from '/@/components/Table';
import moment from 'moment';
import { DICT_TYPE } from '/@/utils/dict';
import { getDate } from '/@/utils/dateUtil';

export const columns: BasicColumn[] = [
  {
    title: '任务编号',
    dataIndex: 'id',
  },
  {
    title: '任务名称',
    dataIndex: 'name',
  },
  {
    title: '所属流程',
    dataIndex: 'processName',
    customRender: ({ record }) => {
      return record.processInstance ? record.processInstance.name : '';
    },
  },
  {
    title: '流程发起人',
    dataIndex: 'startUserNickname',
    customRender: ({ record }) => {
      return record.processInstance ? record.processInstance.startUserNickname : '';
    },
  },

  {
    title: '结果',
    dataIndex: 'result',
    width: 180,
    customRender: ({ text }) => {
      return useRender.renderDict(text, DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT);
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
    customRender: ({ text }) => {
      return useRender.renderDate(text);
    },
  },
  {
    title: '审批时间',
    dataIndex: 'endTime',
    width: 180,
    customRender: ({ text }) => {
      return useRender.renderDate(text);
    },
  },
  {
    title: '耗时',
    dataIndex: 'durationInMillis',
    width: 180,
    customRender: ({ text }) => {
      return getDate(text);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '流程名',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  {
    field: 'createTime',
    label: '创建时间',
    component: 'RangePicker',
    colProps: { span: 8 },
    componentProps: {
      valueFormat: 'X',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '岗位名称',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入岗位名称',
    },
  },
  {
    field: 'code',
    label: '岗位编码',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入岗位编码',
    },
  },
  {
    field: 'status',
    label: '状态',
    defaultValue: 0,
    component: 'Switch',
    colProps: { span: 8 },
    required: true,
    componentProps: {
      checkedValue: 1,
      unCheckedValue: 0,
    },
  },
  {
    field: 'sort',
    label: '序号',
    component: 'Input',
    required: true,
    defaultValue: '255',
    componentProps: {
      placeholder: '请输入岗位序号',
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
];
